var txin=true;
var detailList={};
var f_img = document.querySelector(".f_img");
var rid = window.location.href.split("?")[1].split("=")[1];
//显示评论弹窗show
// 显示发布页面
$(".show").on("click",function(){
    $(".pinglun,#zz").show();
})
//隐藏发布页面
$(".close").on("click",function(){
    $(".pinglun,#zz").hide();
});
//收藏切换
f_img.onclick = function(){
    if (txin == true) {
        $.ajax({
            type:"post",
            url: upUrl + "/collect/addCollect",
            data: {
                rid: rid,
            },
            dataType: "json",
            success:function(data){
                if (data.code == 200) {
                    toastr.success('收藏成功');
                    f_img.src= "../imgs/favorites.png";
                    $('.favorites_text').html('已收藏')
                } else {
                    toastr.success(data.message);
                }
            },
        })
    }else{
        $.ajax({
            type:"post",
            url: upUrl + "/collect/deleteCollectByRid",
            data: {
                rid: 1,
            },
            success:function(data){
                if (data.code == 200) {
                    toastr.success("取消收藏成功!");
                    f_img.src= "../imgs/favorites_.png";
                    $('.favorites_text').html('收藏')
                } else {
                    toastr.success(data.message);
                }
            },
        })
    }
    txin=!txin;
}
$(function(){
    //详情数据
    getDetailList();
    huoqupinglun();
});
function getDetailList () {
    $.ajax({
        type:"get",
        url: upUrl + "/route/getRouteDetail",
        data: {
            rid:rid,
        },
        success:function(data){
            console.log(data.result)
            detailList = data.result
            $('.name').html(detailList.rname)
            $('.jieshao').html(detailList.routeIntroduce)
            $('.lvyou').html(detailList.lvyouxingzhi)
            $('.gongsi').html(detailList.lvyougongsi)
            $('.danjia').html(detailList.price)
            document.querySelector(".nav_img").src= detailList.rimage;
            if (detailList.rflag == '1') {
                document.querySelector(".f_img").src= "../imgs/favorites.png";
                $('.favorites_text').html('已收藏')
            } else {
                document.querySelector(".f_img").src= "../imgs/favorites_.png";
                $('.favorites_text').html('收藏')
            }
            $('.Introduction').html(detailList.rname)
            var orderBody = ''
            $.each(detailList.routeImgList, function (index, val) {
                orderBody += '<img src="' + val.bigpic + '" alt="" alt="">\
                <div class="m_img_text">酒店图片</div>'
            })
            $('.tupian').html(orderBody);
        }
    })
}
function fabu () {
    if ($('.input-hotel-text').val() == '') {
        toastr.error("请输入评论!");
        return;
    }
    $.ajax({
        type:"post",
        url: upUrl + "/evaluate/addEvaluate",
        data: {
            rid:rid,
            score: $('input[name="sex"]:checked').val(),
            comment: $('.input-hotel-text').val(),
            author:JSON.parse(window.sessionStorage.getItem('admin')).name,
            eviewStatus:'1',
            commentTime: new Date(),
        },
        dataType: "json",
        success:function(data){
            toastr.success("评论添加成功!");
            $(".pinglun,#zz").hide();
            huoqupinglun();
            $('.input-hotel-text').val('')
        }
    })
}
function huoqupinglun () {
    $.ajax({
        type:"get",
        url: upUrl + "/evaluate/evaluateListByRid",
        data: {
            rid:rid,
        },
        dataType: "json",
        success:function(data){
            var orderBody = '';
            $.each(data.result, function (index, val) {
                orderBody += '<div class="r_item mt20">\
                        <div class="item_a">\
                            <div class="a_img mr10 "><img class="c_img" src="https://zyn3.gzhnlx.com/uploads/userfiles/1/images/avatar/1-200PQ055128.jpg" alt=""></div>\
                            <div class="a_text">\
                                <span class="a_r_name">' + val.author + '</span>\
                                <div class="mt10" style="font-size: 12px;">' + val.commentTime + '</div>\
                            </div>\
                        </div>\
                        <div class="item_content">' + val.comment + '</div>\
                        <div class="m_reply">\
                            <img class="mr30" src="../imgs/like_f.png" alt="">\
                        </div>\
                    </div>'
            })
            $('.reply_b').html(orderBody);
        }
    })
}
